﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyOnlineScheduling
{
    static class InstanceGenerator
    {
        private static Random random = new Random(3);
        public static int maxTaskDuration = 20, minTaskDuration = 1;
        public static int maxTaskWeight = 20, minTaskWeigth = 1;
        public static int maxArrivalTime = 50;

        public static int randomNumber(int min, int max)
        {
            return random.Next(min, max);
        }

        private static int CompareArrivalTime(Task x, Task y)
        {
            if (x.arrivalTime > y.arrivalTime) return 1;
            else if (x.arrivalTime < y.arrivalTime) return -1;
            else return 0;
        }

        public static Task[] generateRandomTasks(int numberOfTasks)
        {
            Task[] tasks = new Task[numberOfTasks];

            for (int i = 0; i < numberOfTasks; i++)
            {
                tasks[i] = new Task();
                tasks[i].duration = randomNumber(minTaskDuration, maxTaskDuration);
                tasks[i].weight = randomNumber(minTaskWeigth, maxTaskWeight);
                tasks[i].arrivalTime = randomNumber(0, maxArrivalTime);
            }

            Array.Sort<Task>(tasks, CompareArrivalTime);
            return tasks;        
        }

        public static Processor[] generateProcessors(int numberOfProcessors)
        {
            Processor[] processors = new Processor[numberOfProcessors];

            for (int i = 0; i < numberOfProcessors; i++)
            {
                processors[i] = new Processor();
            }

            return processors;           
        }
    }
}
